package net.lgy;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@SpringBootApplication
@Slf4j
public class LgyAiPanApplication {

    public static void main(String[] args) throws UnknownHostException {
        // 只调用一次 SpringApplication.run()，获取应用上下文
        ConfigurableApplicationContext application = SpringApplication.run(LgyAiPanApplication.class, args);
        Environment env = application.getEnvironment();

        // 打印启动日志（建议增加空值判断，避免端口/应用名未配置时抛空指针）
        String appName = env.getProperty("spring.application.name", "lgy-ai-pan"); // 默认值兜底
        String port = env.getProperty("server.port", "8080"); // 默认端口8080兜底
        String hostAddress = InetAddress.getLocalHost().getHostAddress();

        log.info("\n----------------------------------------------------------\n\t" +
                        "Application '{}' is running! Access URLs:\n\t" +
                        "Local: \t\thttp://localhost:{}\n\t" +
                        "External: \thttp://{}:{}\n\t"+
                        "API文档: \thttp://{}:{}/doc.html\n"+
                        "----------------------------------------------------------",
                appName, port, hostAddress, port, hostAddress, port);
    }

}